{% extends "oscar/catalogue/detail.html" %}
{% load compress %}
{% load currency_filters %}
{% load history_tags %}
{% load reviews_tags %}
{% load staticfiles %}
{% load product_tags %}
{% load thumbnail %}
{% load basket_tags %}
{% load i18n %}
{% load price_tags %}

{% block body_class %}product-page{% endblock body_class %}

{% block breadcrumbs %}
<ul class="breadcrumb">
    <li>
        <a href="{% url promotions:home %}">{% trans "Home" %}</a>
        <span class="divider">/</span>
    </li>
    {% with group_product=product.parent|default:product %}
    {% with category=group_product.categories.all.0 %}
        {% for c in category.get_ancestors %}
        <li>
            <a href="{{ c.get_absolute_url }}">{{ c.name }}</a>
            <span class="divider">/</span>
        </li>
        {% endfor %}
        <li class="active">{{ group_product.title }}</li>


    {% endwith %}
    {% endwith %}
</ul>
{% endblock %}

{% block content %}
<article><!-- Start of product page -->

    {% if user.is_authenticated and user.is_staff %}
        <div class="row-fluid">
            <div class="well">
                <a href="{% url dashboard:catalogue-product product.id %}"><button class="btn btn-success btn-full">{% trans "Edit this product" %}</button></a>
            </div>
        </div>
    {% endif %}

    <div class="row-fluid" style="position:relative">

        {% block product_gallery %}
        <div class="span6">
            {% include "catalogue/partials/gallery.html" %}
        </div>
        {% endblock %}

        <div class="span6">
        {% if user.is_authenticated %}
            {% block product_main %}
                <div class="product-highlight">
                    <h4>{{ product.stockrecord.partner.name }}</h4>
                    <h1>{{ product.get_title }}</h1>

                    {% block product_stock_record %}
                        {% if not product.is_group %}
                        <div class="row-fluid">
                            <h2 class="price_color">{% include "catalogue/partials/stock_record.html" %}</h2>
                            <!--<p class="free-delivery"><i class="icon-truck"></i> <span><strong>{% trans "Free shipping" %}</strong> <br/> {% trans "For all orders over $300" %}</span></p>-->
                        </div>
                        {% endif %}
                    {% endblock %}

                    {% block product_description %}
                        {% if product.description %}
                        <p>{{ product.description|safe }}</p>
                        {% endif %}
                    {% endblock %}

                    {% if not product.is_group %}
                        {% block product_basket_form %}
                        <div class="well">
                            {% include "catalogue/partials/add_to_basket_form.html" %}
                        </div>
                        {% endblock %}
                    {% endif %}

            {% endblock %}
            </div>

            {% if product.is_group %}
                <form action="/basket/add/" method="post" class="form-stacked" id="add-to-cart">
                    {% csrf_token %}
                    <span class="help-block"></span>
                    <div class="control-group ">
                        <label for="id_product_id" class="control-label required">{% trans "Talle" %} <span>*</span></label>
                        <div class="controls">
                            <select name="product_id" id="id_product_id">
                            {% for variant in product.variants_ordered_by_size %}
                                <option value="{{variant.id}}">{{variant.size}}  - {% product_price variant user %}  - {{ variant.stockrecord.availability }}</option>
                            {% endfor %}
                            </select>
                        </div>
                    </div>
                    <div class="control-group ">
                        <label for="id_quantity" class="control-label required">{% trans "Quantity" %} <span>*</span></label>
                        <div class="controls">
                            <input type="text" name="quantity" value="1" id="id_quantity" />
                        </div>
                    </div>
                    <div class="form-actions">
                        <button type="submit" class="btn btn-large btn-primary" value="Add to basket">{% trans "Add to basket" %}</button>
                    </div>
                </form>
            {% endif %}
        {% endif %}

            {% if product.is_group %}
                    {% with variants=product.variants.all %}
                    {% if variants|length > 0 %}
                            {% for variant in variants %}
                            {% if  not variant.is_available_to_buy %}
                            <div class="variant-product well">
                                <div>
                                    <h4>{{ variant.title }}</h4>
                                    <div class="variant-form">
                                        <p class="variant-notice">{% trans "You can get an email alert when this product is back in stock." %}</p>
                                        {% include "catalogue/partials/alerts_form.html" with product=variant %}
                                    </div>
                                </div>
                            </div>
                            {% endif %}
                            {% endfor %}
                    {% endif %}
                {% endwith %}
            {% endif %}

            {% block product_info %}
            <h3>{% trans "Product Information" %}</h3>
            <table class="table table-striped table-condensed">
                {% if product.upc %}
                <tr>
                    <th>{% trans "UPC" %}</th><td>{{ product.upc }}</td>
                </tr>
                {% endif %}
                <tr>
                    <th>{% trans "Product class" %}</th><td>{{ product.product_class.name }}</td>
                </tr>
                {% if product.stockrecord %}
                <tr>
                    <th>{% trans "Price (excl. tax)" %}</th><td>{{ product.stockrecord.price_incl_tax|currency }}</td>
                </tr>
                <tr>
                    <th>{% trans "Price (incl. tax)" %}</th><td>{{ product.stockrecord.price_excl_tax|currency }}</td>
                </tr>
                <tr>
                    <th>{% trans "Availability" %}</th>
                    <td>{{ product.stockrecord.availability }}</td>
                </tr>
                {% endif %}
                {% for av in product.attribute_values.all %}
                <tr>
                    <th>{{ av.attribute.name }}</th>
                    <td>{{ av.value }}</td>
                </tr>
                {% endfor %}
                <tr>
                    <td></td>
                    <td></td>
                </tr>
            </table>
            {% endblock %}

            {% block product_review %}
            {% endblock product_review %}

        </div><!-- /span6 -->

    </div><!-- /row-fluid -->

    {% if product.related_products.count %}
        <div class="sub-header">
            <h2>{% trans "Related items" %}</h2>
        </div>
        <ol class="products five">
            {% for product in product.related_products.all|slice:":5" %}
            <li {% if forloop.counter|divisibleby:"5" %}class="no-margin"{% endif %}>{% render_product product %}</li>
            {% endfor %}
        </ol>
    {% endif %}

    {% if product.recommended_products.count %}
        <div class="sub-header">
            <h2>{% trans "Recommended items" %}</h2>
        </div>
        <ol class="products five">
            {% for product in product.recommended_products.all|slice:":5" %}
            <li {% if forloop.counter|divisibleby:"5" %}class="no-margin"{% endif %}>{% render_product product %}</li>
            {% endfor %}
        </ol>
    {% endif %}

    <div class="hr"><i class="icon-noun_project_62"></i></div>

    {% recently_viewed_products %}

</article><!-- End of product page -->
{% endblock content %}

{% block extrascripts %}
{% compress js %}
    {% include "partials/extrascripts.html" %}
{% endcompress %}
{% endblock %}
